/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.validate;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author VANANH
 */
public class PasswordValidator implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String passowrd = (String) value;
        UIInput confirmComponent = (UIInput) component.getAttributes().get("confirm");
        String confirm = (String) confirmComponent.getSubmittedValue();
        
        if(passowrd == null || passowrd.isEmpty() || confirm == null || confirm.isEmpty())
        {
            return;
        }
        
        if(!passowrd.equals(confirm))
        {
            confirmComponent.setValid(false);
            throw new ValidatorException(new FacesMessage("PassWord không trùng nhau!"));
        }
    }
    
}
